/*
- @Author: Wangjun
- @Date: 2022-11-02 17:34:33

  - @LastEditTime: 2023-12-16 15:52:49
  - @LastEditors: wangjun haodreams@163.com

- @Description:自定义数据转存
  - @FilePath: \xr_node_calc\main.go

- hnxr
*/
package main

import (
	"time"

	"gitee.com/haodreams/golib/easyjson"
	"gitee.com/haodreams/golib/env"
	"gitee.com/haodreams/golib/logs"
	"gitee.com/haodreams/libs/easy"
	"gitee.com/haodreams/libs/ee"
	"gitee.com/haodreams/libs/routine"
	"gitee.com/haodreams/op_node/models"
	"gitee.com/haodreams/op_node/routers"

	_ "gitee.com/haodreams/op_node/noderdb" //加载数据库算子
	_ "gitee.com/hnxr_1/nodex/nodeall"      //加载默认的全部算子
)

// 麦杰数据写入ck
func main() {
	env.Setup("conf/app.conf")
	//保证程序只能启动一个，如果端口被占用了， 程序则不再启动
	listener, err := env.CreateListenerTCP()
	if err != nil {
		ee.Print(err, logs.CbError)
		return
	}
	easyjson.Default()
	easy.MkdirAll("data/nodes/pvbox")
	easy.MkdirAll("data/run")
	routine.Start()

	err = models.Setup()
	if err != nil {
		ee.Print(err, logs.CbError)
		return
	}

	//启动网页服务
	err = routers.Setup(listener)
	if err != nil {
		ee.Print(err, logs.Error)
		return
	}
	routine.WaitExit()
	//延迟5秒停止运行，保证有充足的保存操作
	time.Sleep(5 * time.Second)
}
